package ibmetp.mis.tags;

import ibmetp.mis.dao.BulletinDao;
import ibmetp.mis.vo.Bulletin;
import ibmetp.mis.vo.Page;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

public class BulletinTag extends TagSupport{
  private int pageNo=1;//页面号
  private int size=10;//页面大小
  private int top=0;
	@Override
	public int doEndTag() throws JspException {
		BulletinDao db=new BulletinDao();
		pageNo=pageNo>0?pageNo:1;
		size=size>0?size:11;
		try
		{
		
		Page p=db.getBulletinPage(pageNo,size,new Bulletin());
		Bulletin b=null;
		StringBuffer msgs=new StringBuffer("<marquee scrollamount='2' onmouseover='this.stop()' onmouseout='this.start()' direction='left'>");
		StringBuffer mess=new StringBuffer("<div class='bulletins'><div id=\"cc\" class='bulletin'></div><div class='bulletin'><div>");
		
		for(int i=0;i<p.getList().size();i++)
		{  
			b=(Bulletin)p.getList().get(i);
			msgs.append("[<strong style='color:#282828'>"+b.getPublishMsg()+" --"+b.getCreateDate()+"</strong>]&nbsp;&nbsp;&nbsp;&nbsp");
			
			mess.append(b.getPublishMsg());
			mess.append("</div><div class='mark'>");
			mess.append("&nbsp;&nbsp;--");
			mess.append(b.getPrincipal());
			mess.append("&nbsp;&nbsp;");
			mess.append(b.getCreateDate());
			if(p.getList().size()-1==i)
				  mess.append("</div></div>");
					else mess.append("</div></div><div class='bulletin'><div>");
		}
		if(top==1){
		msgs.append("</marquee>");
		this.pageContext.getOut().println(msgs);
		}

		else {
			 mess.append("</div>");
			 //System.out.println(mess);
			this.pageContext.getOut().println("<div class='foot'><a href=\"/MIS/manage/bulletin/bulletin.jsp?pageNo="+p.getPrevPage()+"&size="+size+"\"> <<</a>&nbsp;&nbsp;<a href=\"/MIS/manage/bulletin/bulletin.jsp?pageNo="+p.getNextPage()+"&size="+size+"\"> >></a></div>"+mess);
		}
			
		}
		
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return super.doEndTag();
	}
	public int getSize() {
		return size;
	}
	public void setSize(int size) {
		this.size = size;
	}
	public int getPageNo() {
		return pageNo;
	}
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}
	public int getTop() {
		return top;
	}
	public void setTop(int top) {
		this.top = top;
	}
   
	
	
}
